define(["jquery", "bootstrap", "backend", "table", "form", "jstree"], function (
  $,
  undefined,
  Backend,
  Table,
  Form,
  undefined
) {
  var Controller = {
    index: function () {
      // 初始化表格参数配置
      Table.api.init({
        extend: {
          index_url: "subject/subject/index",
          add_url: "subject/subject/add",
          edit_url: "subject/subject/edit",
          del_url: "subject/subject/del",
          chapter_url:"subject/chapter/index",
          table: "subject",
        },
      });

      //获取table元素
      var table = $("#table");

      // 初始化表格
      table.bootstrapTable({
        url: $.fn.bootstrapTable.defaults.extend.index_url,
        pk: "id",
        sortName: "createtime", //排序方式,根据时间来排序
        // search:false,          //取消快速搜索
        // "columns"：输出的列
        columns: [
          [
            { checkbox: true }, //复选框
            { field: "id", title: __("Id") }, //对应复选框的内容:id
            { field: "title", title: __("Title"), operate: "LIKE" }, //operate表示可搜索键
            //课程图片
            {
              field: "thumb_cdn",
              title: __("ThumbCdn"),
              operate: false,
              events: Table.api.events.image,
              formatter: Table.api.formatter.image,
            },
            //点赞数
            {
              field: "likes",
              title: __("Likes"),
              operate: false,
            },
            //课程价格
            {
              field: "price",
              title: __("Price"),
              operate: false,
            },
            //创建时间
            {
              field: "createtime",
              title: __("CreateTime"),
              operate: false,
              formatter: Table.api.formatter.datetime,
              operate: "RANGE",
              addclass: "datetimerange",
              sortable: true,
            },
            //课程分类选项
            {
              field: "category.name",
              title: __("CategoryName"),
              operate: "LIKE",
            },
            //课程老师选项
            {
              field: "teacher.name",
              title: __("TeacherName"),
              operate: "LIKE",
            },
            //操作选项
            {
              field: "operate",
              title: __("Operate"),
              table: table,
              events: Table.api.events.operate,
              formatter: Table.api.formatter.operate,
              buttons: [
                {
                  name:'chapter',
                  title:'课程章节',
                  classname:'btn btn-info btn-xs btn-dialog',
                  icon:'fa fa-list',                                                    //图标
                  url:$.fn.bootstrapTable.defaults.extend.chapter_url,
                  extend:'data-toggle="tooltip" data-container="body"',                 //继承属性,图标出现自然
              }],
            },
          ],
        ],
      });

      // 为表格绑定事件
      Table.api.bindevent(table);
    },
    add: function () {
      Controller.api.bindevent();
    },
    edit: function () {
      Controller.api.bindevent();
    },
    api: {
      bindevent: function () {
        Form.api.bindevent($("form[role=form]"));
      },
    },
  };

  return Controller;
});
